//
//  XianyiViewController.m
//  A_HandHeldLOL
//
//  Created by Zhao YanBin on 16/1/21.
//  Copyright © 2016年 zhaoyanbin. All rights reserved.
//

#import "XianyiViewController.h"
#import "XianyiTableViewCell.h"
#import "AFNModel.h"
#import <UIImageView+WebCache.h>
#import "XianyiModel.h"
#import "XianyiXiangqingViewController.h"
@interface XianyiViewController ()<UITableViewDataSource, UITableViewDelegate>
@property(nonatomic, retain)UITableView *tableView;
@property(nonatomic, retain)NSMutableArray *dataArr;
@property(nonatomic, retain)NSDictionary *dic;
@end

@implementation XianyiViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
    //导航名称
    self.navigationItem.title = @"现役成员";
    
    //tableView
    [self creatableView];
    
    //数据处理
    [self data];
}

-(void)creatableView
{
    self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [self.view addSubview:_tableView];
    [_tableView release];
    
    [self.tableView registerClass:[XianyiTableViewCell class] forCellReuseIdentifier:@"xianyi"];
}

//数据处理
-(void)data
{
    NSString *str1 = @"http://qt.qq.com/php_cgi/lol_mobile/club/varcache_team_members.php?id=";
    NSString *str2 = @"&plat=ios&version=3";
    NSString *str = [NSString stringWithFormat:@"%@%@%@",str1,_detailsid,str2];    [AFNModel GETWithURL:str completion:^(id result) {
        NSArray *arr = result[@"members"];
        self.dataArr = [XianyiModel modelHanderWithArray:arr];
        
        [self.tableView reloadData];
    }];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _dataArr.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    XianyiTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"xianyi" forIndexPath:indexPath];
    XianyiModel *m = _dataArr[indexPath.row];
    cell.name.text = m.name;
    cell.neirong.text = m.intro;
    [cell.img sd_setImageWithURL:[NSURL URLWithString:m.iconUrl]];
   
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 120;
}

//cell点击方法
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    XianyiXiangqingViewController *xqVC = [[XianyiXiangqingViewController alloc] init];
    xqVC.duiyuanid = [_dataArr[indexPath.item] Id];
    [self.navigationController pushViewController:xqVC animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
